<include file="Public:header" />
<script type="text/javascript">
function KindEditorReady(){
	KindEditor.ready(function(K) {
	  var editor = K.editor({
		  allowFileManager : true,
		  uploadJson : "{:U('/Common/uploadEditor')}"
	  });
	  $('.imagesBtn').live("click", function() {
		  var obj = $(this);
		  editor.loadPlugin('easyimage', function() {
			  editor.plugin.imageDialog({
				  //imageUrl : K('#url1').val(),
				  clickFn : function(url, title, width, height, border, align) {
					  //K('#url1').val(url);
					  //$("#imageUrl img").attr({src:url, alt:title});
					   obj.closest("td").find(".bw-image").val(url);
					  //$("#imageUrl").show();
					  editor.hideDialog();
				  }
			  });
		  });
		  return false;
	  });
	});
}

$(function(){
	function resetRowSortTr(){
	 //重置排序
	 $(".flash_pic_table tbody tr").each(function(index, element) {
        $(this).find("input[name^='row_sort']").val(index+1);
    });
}	

  $(".ajaxAdd").click(function(){
    if(Number($(".ajaxAdd").length) < 10){
      $(this).closest("tr").clone(true).find("input").not(".imagesBtn").val("").end().closest("tr").appendTo(".flash_pic_table");
	  resetRowSortTr();
    }else{
      alert("你最多可以添加10张图片");  
    }
  });
  $(".ajaxDel").click(function(){
    if(Number($(".ajaxAdd").length) > 1){
      $(this).closest("tr").remove();
	  resetRowSortTr();
    }
  });
  
  $(".ajaxUp").click(function(){
     var thisTrIndex = $(this).closest("tr").index();
	 if(thisTrIndex > 0){
		 $(this).closest("tr").after($(".flash_pic_table tbody tr").eq(thisTrIndex-1)); 
     }else{
		 alert('已经是第一个位置了');
		 return false;
	 }
	 resetRowSortTr();
  });
  
  $(".ajaxDown").click(function(){
     var thisTrIndex = $(this).closest("tr").index();
	 var allTrLength = $(".flash_pic_table tbody tr").length;
	 
	 if(thisTrIndex < allTrLength-1){
		 $(this).closest("tr").before($(".flash_pic_table tbody tr").eq(thisTrIndex+1)); 
     }else{
		 alert('已经是最后一个位置了');
		 return false;
	 }
	  resetRowSortTr();
  });
  
});
KindEditorReady(); //初始化
</script>
<h3 class="title"> <em>新增轮播广告</em> <include file="nav" /> </h3>
<div class="formbox">
  <form name="mform" id="mform" method="post" action="{:U('add')}" enctype="multipart/form-data">
    <table width="100%" border="0" cellspacing="1" cellpadding="0">
      <tr>
        <th>广告名称：</th>
        <td><input name="name" type="text" class="ipt" id="name" size="50" maxlength="50" value="" /></td>
      </tr>
      <tr>
        <td width="100" align="right">轮播广告</td>
        <td><table cellpadding="0" cellspacing="0" width="100%" class="flash_pic_table">
            <tr>
              <td valign="middle">图片:<br>
                链接:<br>
                标题:</td>
              <td>
              <input type="text" name="flash[]" id="flash[]" class="ipt bw-image" size="30" /><input type="button" class="imagesBtn" value="插入图片" />
                <br>
                <input type="text" name="flash_url[]" class="ipt" size="30" />
                <br>
                <input type="text" name="flash_title[]" class="ipt" size="30" /></td>
              <td valign="middle">nofollow:</td>
              <td valign="middle"><select name="nofollow[]">
                  <option value="0">否</option>
                  <option value="1">是</option>
                </select></td>
              <td><input type="hidden" name="row_sort[]" size="2" value="{$key+1}" /><a href="###" class="add ajaxUp">上移</a>&nbsp;<a href="###" class="add ajaxDown">下移</a>&nbsp;<a href="###" class="add ajaxAdd">继续添加</a> &nbsp; <a href="###" class="del ajaxDel">删除</a></td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <th valign="top">备注：</th>
        <td><textarea name="remark" cols="55" rows="8" class="ipt" id="remark"></textarea></td>
      </tr>
      <tr>
        <th>状态：</th>
        <td><label>
            <input name="status" type="radio" value="1" checked="checked" />
            显示 </label>
          <label>
            <input name="status" type="radio" value="2" />
            不显示 </label></td>
      </tr>
      <tr class="btnbox">
        <th>&nbsp;</th>
        <td><input type="hidden" value="2" name="ad_type" />
          <input type="submit" class="btn" value="保 存">
          &nbsp;
          <input type="reset" class="btn" value="取 消" onClick="window.location.href='{:U('index')}';"></td>
      </tr>
    </table>
  </form>
</div>
<include file="Public:footer" />